// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  console.log ('club为'+event.myclub)
  console.log ('openid为'+event._openid)
  console.log('club id 为：'+event.clubid)
  console.log('joinmember为：'+event.joinmember)
  const db = cloud.database();
  const user = db.collection('user');
  const clubco = db.collection('club');
 try {
  await  user.where({
    _openid: event._openid
  }).update({
    data:{ 
      myclub:event.myclub,
    }
  })
  await clubco.doc(event.clubid).update({
    data:{
      joinmember:event.joinmember,
    }
  })



  } catch (err) {
    console.log(err)
  }




  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}